package com.mall.service.marketing.controller;

import com.mall.autoconfig.interceptor.BaseContext;
import com.mall.commons.common.CommonResult;
import com.mall.model.vo.PageResult;
import com.mall.service.marketing.service.SmsCouponHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/couponHistory")
public class SmsCouponHistoryController {

    @Autowired
    private SmsCouponHistoryService smsCouponHistoryService;

    /**
     * 根据优惠券id，使用状态，订单编号分页获取领取记录
     * @param couponId
     * @param orderSn
     * @param useStatus
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam(value = "couponId", required = false) Long couponId,
                             @RequestParam(value = "orderSn", required = false) String orderSn,
                             @RequestParam(value = "useStatus", required = false) Integer useStatus,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        log.info("当前用户id={}", BaseContext.getCurrentId());
        PageResult pr = smsCouponHistoryService.list(couponId, useStatus, orderSn, pageSize, pageNum);
        return CommonResult.success(pr);
    }
}
